package cn.gov.pbc.gd.credit.web.controller.user;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.liu.jbase.PageListVo;
import com.liu.jbase.ResultVo;
import com.liu.jbase.controller.impl.BaseControllerImpl;

import cn.gov.pbc.gd.credit.user.service.online.IOnlineUserService;
import cn.gov.pbc.gd.credit.user.service.user.IUserService;
import cn.gov.pbc.gd.credit.vo.online.OnlineUserVo;
import cn.gov.pbc.gd.credit.vo.user.ResUserVo;
import cn.gov.pbc.gd.credit.vo.user.UserVo;

@Controller
@RequestMapping("/user")	
public class UserController extends BaseControllerImpl<ResUserVo, UserVo, IUserService> {

	@Autowired
	private IUserService userService;
	
	@Autowired
	private IOnlineUserService onlineUserService;
	
	@ResponseBody
	@RequestMapping("/modify/pwd")
	public ResultVo<ResUserVo> modifyPwd(UserVo vo, HttpServletRequest request){//修改用户登陆密码
		
        ResultVo<ResUserVo> result = new ResultVo<ResUserVo>();
        
		result = userService.modifyPwd(vo);
		
		return result;
	}
	
	@ResponseBody
	@RequestMapping("/default/pwd")
	public ResultVo<ResUserVo> defaultPwd(UserVo vo, HttpServletRequest request){//恢复缺省密码
		
        ResultVo<ResUserVo> result = new ResultVo<ResUserVo>();
        
		result = userService.defaultPwd(vo, request);
		
		return result;
	}
	
	@ResponseBody
	@RequestMapping("/modify/status")
	public ResultVo<ResUserVo> modifyStatus(UserVo vo, HttpServletRequest request){//修改用户登陆密码
		
        ResultVo<ResUserVo> result = userService.updateStatus(vo, request);
		
		return result;
	}
	
	@ResponseBody
	@RequestMapping("/update/head/img")
	public ResultVo<String> updateHeadImg(UserVo vo, HttpServletRequest request){
		
		return userService.updateHeadImg(vo, request);
	}
	
	@RequestMapping("/cert/head/img")
	public String certHeadImg(UserVo vo, Model model, HttpServletRequest request){
		
        model.addAttribute("id", vo.getId());
		
		return "user/certHeadImg";
	}
	
	@RequestMapping("/head/img/view")
	public String headImgView(UserVo vo, Model model, HttpServletRequest request){
		
        model.addAttribute("id", vo.getId());
		
		return "user/modifyHead";
	}
	
	@RequestMapping("/online/page")
	public String online(UserVo vo,  Model model, HttpServletRequest request){
		
		ResultVo<PageListVo<OnlineUserVo>> resultVo = onlineUserService.page(vo, request);
		model.addAttribute("result", resultVo);		
		return "user/online";
	}
	
	@ResponseBody
	@RequestMapping("/sign/name")
	public ResultVo<String> userSign(UserVo vo, HttpServletRequest request){//用户签名
		
        ResultVo<String> result = userService.userSign(vo, request);
		
		return result;
	}
	
	@RequestMapping("/sign/page")
	public String userPage(UserVo vo, Model model, HttpServletRequest request){//用户签名
		
        model.addAttribute("result", userService.find(vo, request));
		
		return "user/signName";
	}
	
	@ResponseBody
	@RequestMapping("/query/operater/list")
	public ResultVo<List<ResUserVo>> queryOperaterList(UserVo vo, HttpServletRequest request){//用户签名
		
		ResultVo<List<ResUserVo>> result = userService.queryOperaterList(vo, request);
		
		return result;
	}
}
